var cur = 1;
function checkItems(isUrl,_url,_params){
	console.log(cur);
	var dataNum = $("#data");
	var dataFormat = dataNum.attr("data");
	dataFormat = eval('(' + dataFormat + ')');//转化成Object
	var url = dataFormat.url;
	if(isUrl){
		url = _url;
	}
	var pageSize = dataFormat.pageSize;
	var rows = dataFormat.rows;
	var th = '<th width="25"><input type="checkbox" name="" value=""></th>';
	var values = [];
	for(var i = 0; i < rows.length; i++){
		var row = rows[i];
		var w = row.w;
		var name = row.name;
		th+='<th width="'+row.w+'">'+row.name+'</th>';
		values[i] = row.value;
	}
	dataNum.html(th);
	var data = {pageSize:pageSize,cur:cur,orderby:'createtime'};
	for(var i = 0; i < _params.length; i++){
		data[_params[i].name] = _params[i].value;
	}
	params = {url:url,data:data,dataType: 'json',type:'post',success:function(data){
		console.log(data);
		console.log(values);
		var tr = "";
		var tbody = $("#tbody");
		if(data.code == 0){
			models = data.models;
			for(var i = 0; i < models.length; i++){
				var model = models[i];
				tr += '<tr class="text-c"><td><input type="checkbox" value="1" name=""></td>';
				for(var j = 0; j < values.length;j++){
					if(values[j] == 'createtime'){
						tr+= '<td>'+ new Date(model[values[j]].time).toLocaleString().replace(/年|月/g, "-").replace(/日/g, " ")+'</td>';
					}else
						tr+='<td>'+model[values[j]]+'</td>';
				}
				tr+="</tr>";
			}
		}
		tbody.html(tr);
		
		//设置翻页代码
		var page = data.model;
		var start = (page.cur) * page.pageSize;
		var end = start + page.pageSize;
		
		var pageRow = page.total/page.pageSize;
		$("#pageData").html('显示'+start+' 到 '+end+'条 ，共 '+page.total+' 条,每页显示'+page.pageSize+'条,共'+(page.total/page.pageSize)+"页");
		
		var pageNumberHtml = '<a id="pageUp" class="paginate_button previous disabled">上一页</a>';
		
		for(var pageIndex = page.cur - 3; pageIndex < (page.total/page.pageSize) && pageIndex < 3 + page.cur == 1; pageIndex++){
			if(pageIndex >= 0)
			if(pageIndex == page.cur){
				pageNumberHtml += '<span><a class="paginate_button pageIndex current">'+(pageIndex+1)+'</a></span>'
			}else 
				pageNumberHtml += '<span><a class="paginate_button pageIndex">'+(pageIndex+1)+'</a></span>'
		}
		pageNumberHtml += '<a id="pageNext" class="paginate_button next disabled">下一页</a>';
		$("#pageNumber").html(pageNumberHtml);
		//绑定分页事件
		$("#pageNext").click(function(){
			if(cur < page.total/page.pageSize) cur++;
			console.log(cur);
			checkItems(isUrl,_url,_params);
		});
		$(".pageIndex").click(function(e){
			console.log($(this).text());
			cur = parseInt($(this).text());
			checkItems(isUrl,_url,_params);
		});
		$("#pageUp").click(function(){
			if(cur > 1) cur--;
			checkItems(isUrl,_url,_params);
		});
	}};
	$.ajax(params);
}
$(function(){		
	checkItems(false,"",[]);
});